package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jt.pojo.Item;
import com.jt.vo.EasyUITable;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jt.mapper.ItemMapper;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ItemMapper itemMapper;

    /**
     * 分页sql
     * 查询第一页：
     * select
     * <p>
     * <p>
     * 查询第二页
     * <p>
     * <p> 查询第三页
     */
    @Override
    public EasyUITable findItemByPage(int page, int rows) {
//		long total=itemMapper.selectCount(null);
//		int startIndex =(page - 1) * rows;
//		List<Item> itemList=itemMapper.findItemByPage(startIndex,rows);

        /*2.利用MP方式实现分页*/
        IPage mpPage = new Page(page, rows);
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("updated");
        mpPage = itemMapper.selectPage(mpPage, queryWrapper);
        long total = mpPage.getTotal();
        List<Item> itemList = mpPage.getRecords();
        return new EasyUITable(total, itemList);


    }


}
